package translated;

import java.util.List;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.model.structure.*;
import edu.pku.sei.modeler.jet.util.*;

public class EditpartFactoryGen
{
  protected static String nl;
  public static synchronized EditpartFactoryGen create(String lineSeparator)
  {
    nl = lineSeparator;
    EditpartFactoryGen result = new EditpartFactoryGen();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "/**" + NL + " * Copyright (c) Software Institute of PKU" + NL + " * All rights reserved. " + NL + " * This program and the accompanying materials" + NL + " * are made available under the terms of the Eclipse Public License v1.0" + NL + " * which accompanies this distribution, and is available at" + NL + " * http://www.eclipse.org/legal/epl-v10.html" + NL + " *" + NL + " */" + NL + "package ";
  protected final String TEXT_2 = ";" + NL + "" + NL + "import org.eclipse.gef.EditPart;" + NL + "" + NL + "import edu.pku.sei.modeler.model.structure.*;" + NL + "import edu.pku.sei.modeler.edit.parts.AbstractEditPartFactory;" + NL + "import edu.pku.sei.modeler.model.core.MetaElement;" + NL + "import edu.pku.sei.modeler.model.structure.MetaShapeElement;";
  protected final String TEXT_3 = NL + "import ";
  protected final String TEXT_4 = ".*;";
  protected final String TEXT_5 = NL + NL + "/**" + NL + " * @generated" + NL + " *" + NL + " */" + NL + "public class ModelEditpartFactory extends AbstractEditPartFactory {" + NL + "\tpublic EditPart createEditPart(MetaShapeElement shape) {" + NL + "\t\tEditPart part = null;" + NL + "\t\tMetaElement content = shape.getModelElement();" + NL + "\t\tif (false){" + NL + "\t\t\tpart = null;" + NL + "\t\t}" + NL + "\t\t";
  protected final String TEXT_6 = NL + "\t\telse if(content instanceof ";
  protected final String TEXT_7 = ") {" + NL + "\t\t\tpart = new ";
  protected final String TEXT_8 = "Editpart(shape);" + NL + "\t\t\t";
  protected final String TEXT_9 = NL + "\t\t\tMetaLocationManager mgr = new MetaLocationManager();" + NL + "\t\t\t";
  protected final String TEXT_10 = " locator = new ";
  protected final String TEXT_11 = "();" + NL + "\t\t\t";
  protected final String TEXT_12 = NL + "\t\t\tlocator.setAxisDirection(";
  protected final String TEXT_13 = ");" + NL + "\t\t\tlocator.setPositionType(";
  protected final String TEXT_14 = ");" + NL + "\t\t\tlocator.setPosition(";
  protected final String TEXT_15 = ");" + NL + "\t\t\tlocator.setHeadMargin(";
  protected final String TEXT_16 = ");" + NL + "\t\t\tlocator.setMiddleSpacing(";
  protected final String TEXT_17 = ");" + NL + "\t\t\tlocator.setTailMargin(";
  protected final String TEXT_18 = ");" + NL + "\t\t\tlocator.setBreadth(";
  protected final String TEXT_19 = ");" + NL + "\t\t\t";
  protected final String TEXT_20 = NL + "\t\t\tlocator.setSize(";
  protected final String TEXT_21 = ");" + NL + "\t\t\t";
  protected final String TEXT_22 = NL + "\t\t\tlocator.setDirection(";
  protected final String TEXT_23 = ");" + NL + "\t\t\tlocator.setNumPerSide(";
  protected final String TEXT_24 = ");" + NL + "\t\t\t";
  protected final String TEXT_25 = NL + "\t\t\tmgr.setLocator(locator);" + NL + "\t\t\tmgr.setManageClass(\"";
  protected final String TEXT_26 = ".";
  protected final String TEXT_27 = "\");" + NL + "\t\t\tmgr.setRefName(\"";
  protected final String TEXT_28 = "\");" + NL + "\t\t\tif(shape instanceof MetaNode) {" + NL + "\t\t\t\t((MetaNode)shape).getLocationMgrs().add(mgr);" + NL + "\t\t\t}" + NL + "\t\t\t";
  protected final String TEXT_29 = NL + "\t\t}" + NL + "\t\t";
  protected final String TEXT_30 = NL + "\t\telse {" + NL + "\t\t\tpart = super.createEditPart(shape);" + NL + "\t\t}" + NL + "\t\treturn part;" + NL + "\t}" + NL + "}";
  protected final String TEXT_31 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     List modelList = (List) argument; 
    stringBuffer.append(TEXT_1);
    stringBuffer.append(ModelerConstants.pkgBase + "." + ModelerConstants.editpartBase);
    stringBuffer.append(TEXT_2);
    
	List pkgPaths = PackageRetriever.pkgPathList;
	for(int i=0; i<pkgPaths.size(); i++) {

    stringBuffer.append(TEXT_3);
    stringBuffer.append(pkgPaths.get(i));
    stringBuffer.append(TEXT_4);
    
	}

    stringBuffer.append(TEXT_5);
    
		for(int i=0; i<modelList.size(); i++) {
			MetaClass cls = (MetaClass)modelList.get(i);
		
    stringBuffer.append(TEXT_6);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_8);
    
				List mgrs = cls.getModel().getLocationManagers(cls.getElementID());
				for(int j=0; j<mgrs.size(); j++) {
					MetaLocationManager mgr = (MetaLocationManager)mgrs.get(j);
					AbstractLocator locator = mgr.getLocator();
			
    stringBuffer.append(TEXT_9);
    stringBuffer.append(locator.getType());
    stringBuffer.append(TEXT_10);
    stringBuffer.append(locator.getType());
    stringBuffer.append(TEXT_11);
    
					if(locator instanceof ActivationLocatorAdapter) {
						ActivationLocatorAdapter real = (ActivationLocatorAdapter)locator;
			
    stringBuffer.append(TEXT_12);
    stringBuffer.append(real.getAxisDirection());
    stringBuffer.append(TEXT_13);
    stringBuffer.append(real.getPositionType());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(real.getPosition());
    stringBuffer.append(TEXT_15);
    stringBuffer.append(real.getHeadMargin());
    stringBuffer.append(TEXT_16);
    stringBuffer.append(real.getMiddleSpacing());
    stringBuffer.append(TEXT_17);
    stringBuffer.append(real.getTailMargin());
    stringBuffer.append(TEXT_18);
    stringBuffer.append(real.getBreadth());
    stringBuffer.append(TEXT_19);
    
					}
					else if(locator instanceof PinLocatorAdapter) {
						PinLocatorAdapter real = (PinLocatorAdapter)locator;
			
    stringBuffer.append(TEXT_20);
    stringBuffer.append(real.getSize());
    stringBuffer.append(TEXT_21);
    
					}
					else if(locator instanceof PortLocatorAdapter) {
						PortLocatorAdapter real = (PortLocatorAdapter)locator;
			
    stringBuffer.append(TEXT_22);
    stringBuffer.append(real.getDirection());
    stringBuffer.append(TEXT_23);
    stringBuffer.append(real.getNumPerSide());
    stringBuffer.append(TEXT_24);
    						
					}
			
    stringBuffer.append(TEXT_25);
    stringBuffer.append(ModelerConstants.pkgBase + "." + ModelerConstants.modelBase);
    stringBuffer.append(TEXT_26);
    stringBuffer.append(mgr.getManageClass());
    stringBuffer.append(TEXT_27);
    stringBuffer.append(mgr.getRefName());
    stringBuffer.append(TEXT_28);
    
				}
			
    stringBuffer.append(TEXT_29);
    
		}
		
    stringBuffer.append(TEXT_30);
    stringBuffer.append(TEXT_31);
    return stringBuffer.toString();
  }
}
